package view;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;

public class FriendList extends Application {
    public Parent parent;
    static Stage stage;
    private double yOffSet;

    public void start(Stage stage1) throws IOException {
        parent = FXMLLoader.load(getClass().getResource("fxml/friendList.fxml"));
        stage1.initStyle(StageStyle.TRANSPARENT);//透明标题栏
        AtomicReference<Double> xOffSet = new AtomicReference<>((double)0);
        //窗口拖动事件
        stage1.initStyle(StageStyle.UNDECORATED);
        parent.setOnMousePressed(event -> {
            xOffSet.set(event.getSceneX());
            yOffSet = event.getSceneY();
        });
        parent.setOnMouseDragged(event -> {
            stage1.setX(event.getScreenX() - xOffSet.get());
            stage1.setY(event.getScreenY() - yOffSet);
        });
        stage1.setTitle("好友列表");
        stage1.setScene(new Scene(parent,300,600));
        stage1.setResizable(false);
        stage1.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

    public void showWindow() throws Exception{
        start(stage);
    }
}
